package config

import (
	"fmt"

	log "github.com/sirupsen/logrus"

	"os"

	"gopkg.in/yaml.v2"
)

var (
	Config           = new(config)
	Auth             string
	BuildInformation = map[string]string{}
)

func init() {
	dir, _ := os.Getwd()
	log.Debugln(dir)
	configFile, err := os.Open("config.yaml")
	if err != nil {
		fmt.Println(err)
		Config = &config{
			Harbor: harbor{
				Username: "admin",
				Password: "",
				Email:    "admin@example.com",
			},
			Redis: redisConfig{
				Addr:     "redis_server:6379",
				Password: "",
				Key: map[string]string{
					"ctf": "ctf",
					"lab": "lab",
				},
				DB: 11,
			},
			Docker: docker{
				Host:                      "",
				DefaultRandomStringLength: 16,
			},
			Minio: minioConfig{
				Host:   "",
				Key:    "",
				Secret: "",
				Secure: false,
			},
			GinMode: "debug",
		}
		fmt.Println("json data error", err)
		return
	} else {
		decoder := yaml.NewDecoder(configFile)
		_ = decoder.Decode(Config)
	}
	defer configFile.Close()
	fmt.Println(Config)

	Auth = initAuth(Config.Harbor.Username, Config.Harbor.Username, Config.Harbor.Email)

}
